package com.wnhz.work.yz.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wnhz.work.yz.R;
import com.wnhz.work.yz.bean.ProjectScheduleBean;

import java.util.List;

/**
 * Created by admin on 2016/12/28.
 */
public class ProjectScheduleAdapter extends BaseAdapter {
    private Context context;
    private List<ProjectScheduleBean> beanList;
    private View.OnClickListener listener;

    public ProjectScheduleAdapter(Context context, List<ProjectScheduleBean> beanList, View.OnClickListener listener) {
        this.context = context;
        this.beanList = beanList;
        this.listener = listener;
    }

    @Override
    public int getCount() {
        return beanList.size();
    }

    @Override
    public Object getItem(int position) {
        return beanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ProjectScheduleViewHolder viewHolder = new ProjectScheduleViewHolder();
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.project_schedule_item, null);
            viewHolder.iv_type = (ImageView) convertView.findViewById(R.id.iv_type);//状态图标
            viewHolder.tv_title = (TextView) convertView.findViewById(R.id.tv_title);//标题
            viewHolder.tv_time = (TextView) convertView.findViewById(R.id.tv_time);//时间
            viewHolder.tv_shenqing = (TextView) convertView.findViewById(R.id.tv_shenqing);//状态
            viewHolder.tv_type = (TextView) convertView.findViewById(R.id.tv_type);
            viewHolder.tv_price = (TextView) convertView.findViewById(R.id.tv_price);//金额
            viewHolder.tv_goods_number = (TextView) convertView.findViewById(R.id.tv_goods_number);//数量
            viewHolder.tv_look = (TextView) convertView.findViewById(R.id.tv_look);//查看
            viewHolder.tv_inventory = (TextView) convertView.findViewById(R.id.tv_inventory);//清单

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ProjectScheduleViewHolder) convertView.getTag();
        }

        if ("1".equals(beanList.get(position).getType())) {
            viewHolder.iv_type.setImageResource(R.mipmap.ic_tihuan);
            viewHolder.tv_title.setText("替换");
            viewHolder.tv_look.setText("查看方案");
            viewHolder.tv_inventory.setVisibility(View.GONE);
        } else if ("2".equals(beanList.get(position).getType())) {
            viewHolder.iv_type.setImageResource(R.mipmap.ic_shouhoutuikuan);
            viewHolder.tv_title.setText("售后-退款");
            viewHolder.tv_look.setText("查看详情");
            viewHolder.tv_inventory.setVisibility(View.GONE);
        } else if ("3".equals(beanList.get(position).getType())) {
            viewHolder.iv_type.setImageResource(R.mipmap.ic_xinzeng);
            viewHolder.tv_title.setText("新增");
            viewHolder.tv_look.setText("查看订单");
            viewHolder.tv_inventory.setVisibility(View.GONE);
        } else if ("4".equals(beanList.get(position).getType())) {
            viewHolder.iv_type.setImageResource(R.mipmap.ic_fahuo);
            viewHolder.tv_title.setText("发货");
            viewHolder.tv_look.setText("查看物流");
            viewHolder.tv_inventory.setVisibility(View.VISIBLE);
        }

        viewHolder.tv_look.setOnClickListener(listener);
        viewHolder.tv_look.setTag(position);
        viewHolder.tv_inventory.setOnClickListener(listener);
        viewHolder.tv_inventory.setTag(position);

        return convertView;
    }

    class ProjectScheduleViewHolder {
        ImageView iv_type;
        TextView tv_title;
        TextView tv_time;
        TextView tv_shenqing;
        TextView tv_type;
        TextView tv_price;
        TextView tv_goods_number;
        TextView tv_look;
        TextView tv_inventory;
    }
}
